#include "encoder.h"

Encoder::Encoder()
{

}

Encoder::Encoder(QString encoderPath,QObject* parent){

    this->encoderPath = encoderPath;
    this->program = encoderPath+"/qrencode";
    this->process=new QProcess(parent);
    this->tempFile = QDir::tempPath()+"/temp.png";

    QObject::connect(process, SIGNAL(finished(int,QProcess::ExitStatus)),
                          this, SLOT(sendImage()));


}

Encoder::~Encoder()
{

}

void Encoder::sendImage(){
    this->img = QImage(tempFile);
    emit imageLoaded(img);
}

bool Encoder::encode(QHash<QString, QString> arguments)
{
        QStringList params;

        foreach (QString value, arguments){
            if(arguments.key(value)=="data")
                continue;
            params <<  arguments.key(value) << value;
        }
        params<< "-o" <<tempFile<< arguments["data"] ;

        process->start(program, params);

    return true;
}
